﻿#pragma once
#include "export_dll.h"
#include "util_types.h"
#include <exception>
#include <iostream>
#include <string>

namespace yzrilyzr_lang{
	class String;

	class U_EXPORT_API Exception : public std::exception{
		protected:
		std::string msg_;
		public:
		explicit Exception(){
			std::cout << "Exception build" << std::endl;
		}

		explicit Exception(const String & message);

		explicit Exception(int32_t code) : msg_(std::to_string(code)){
			std::cout << "Exception build: code: "<< code << std::endl;
		}

		const char * what() const noexcept override{ return msg_.c_str(); }

		void printStackTrace() const noexcept{
			std::cout << what() << std::endl;
		}
	};

	class U_EXPORT_API RuntimeException : public Exception{
		public:
		using Exception::Exception; // 直接继承构造函数
	};

	class U_EXPORT_API IllegalStateException : public Exception{
		public:
		using Exception::Exception; // 直接继承构造函数
	};

	class U_EXPORT_API NoSuchElementException : public Exception{
		public:
		using Exception::Exception; // 直接继承构造函数
	};

	class U_EXPORT_API ConcurrentModificationException : public Exception{
		public:
		using Exception::Exception; // 直接继承构造函数
	};

	class U_EXPORT_API IOException : public Exception{
		public:
		using Exception::Exception; // 直接继承构造函数
	};

	class U_EXPORT_API IndexOutOfBoundsException : public Exception{
		public:
		using Exception::Exception;
	};

	class U_EXPORT_API EOFException : public IOException{
		public:
		using IOException::IOException;
	};

	class U_EXPORT_API NullPointerException : public Exception{
		public:
		using Exception::Exception;
	};

	class U_EXPORT_API UnsupportedOperationException : public Exception{
		public:
		using Exception::Exception;
	};

	class U_EXPORT_API FormatException : public Exception{
		public:
		using Exception::Exception;
	};

	class U_EXPORT_API IllegalArgumentException : public Exception{
		public:
		using Exception::Exception;
	};
	class U_EXPORT_API OutOfMemoryError : public Exception{
		public:
		using Exception::Exception;
	};
	class U_EXPORT_API ArrayIndexOutOfBoundsException : public Exception{
		public:
		using Exception::Exception;
		explicit ArrayIndexOutOfBoundsException(u_index index);
	};
	class U_EXPORT_API UnsupportedEncodingException : public Exception{
		public:
		using Exception::Exception;
	};
	class U_EXPORT_API NumberFormatException : public IllegalArgumentException{
		public:
		using IllegalArgumentException::IllegalArgumentException;
		static NumberFormatException forInputString(const String &s, int32_t radix);
	};
	class U_EXPORT_API SocketException : public IOException{
		public:
		using IOException::IOException;
	};
	class U_EXPORT_API SecurityException : public RuntimeException{
		public:
		using RuntimeException::RuntimeException;
	};
}